"""
Tensor的变形操作
- torch.reshape(input, shape)
- torch.t(input) 只针对2D tensor转置
- torch.transpose(input, dim0, dim1) 交换2个维度
- torch.squeeze(input, dim=None, out=None)去除维度大小为1的维度
- torch.unbind(tensor, dim=0)去除某个维度
- torch.unsqueeze(input, dim, out=None)在指定位置添加维度
- torch.flip(input,dims) 按照给定维度翻转张量
- torch.rot90(input, k, dims) 按照指定维度和旋转次数进行张量旋转

"""
import torch

# a = torch.rand(2, 3)
# print(a)
# out = torch.reshape(a, (3, 2))
# print(out)
# print(torch.t(out))
# print(torch.transpose(out, 0, 1))

a = torch.rand(1, 2, 3)
print(a)
out = torch.transpose(a, 0, 1)
print(out)
out = torch.squeeze(a)
print(out)
print(out.shape)
out = torch.unsqueeze(a, -1)
print(out)
print(out.shape)

out = torch.unbind(a, dim=2)
print(out)
print(a)
print(torch.flip(a, dims=[1, 2]))
print(a)
out = torch.rot90(a, -1)
print(out)
print(out.shape)

